<%@ page language="java" contentType="text/html; charset=UTF-8"
		 pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<link href="${ctx }/js/plugs/jquery-ui-1.10.3.custom/css/mycss/jquery-ui-1.10.3.custom.css" rel="stylesheet" type="text/css" />
	<link rel="stylesheet" href="${ctx }/js/plugs/bootstrap-3.3.0-dist/dist/css/bootstrap.css">
	<!-- 可选的Bootstrap主题文件（一般不用引入） -->
	<!-- <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap-theme.min.css"> -->
	<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
	<!-- <script src="http://cdn.bootcss.com/bootstrap/3.3.0/js/bootstrap.min.js"></script> -->
	<script src="${ctx }/js/plugs/bootstrap-3.3.0-dist/dist/js/bootstrap.js"></script>
	<!-- <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"> -->
	<link href="${ctx }/js/plugs/font-awesome-4.2.0/css/font-awesome.css" rel="stylesheet">

	<title>活动</title>
	<script type="text/javascript">

        $(document).ready(function(){
            currentMenu("lotterymanager");
        });
        function bindSurvey(id){
            window.open("/sy/lottery/surveylist.do?activityId="+id,"关联问卷","height=800, width=1024, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no");

        }
        function removeActivity(id){
            if(confirm("确定删除此活动吗？")){
                var url = "/sy/lottery/removeActivityAjax.do";
                var data="id="+id;
                $.ajax({
                    url:url,
                    data:data,
                    type:"post",
                    success:function(data){
                        if (data == "0") {
                            alert("此活动绑定的试卷已设置奖项，无法删除");
                        } else {
                            alert("删除成功");
                            window.location.reload(true);
                        }
                    }
                });
            }
        }
        function setPrize(id){
            var url = "/sy/lottery/checkActivityStatusAjax.do";
            var data="id="+id;
            $.ajax({
                url:url,
                data:data,
                async:false,
                type:"post",
                success:function(data){
                    if (data == "0") {
                        alert("未关联问卷，无法设置奖项");
                    } else {
                        window.location.href="/sy/lottery/prize/init.do?id="+id;
                        window.event.returnValue = false;
                    }
                }
            });
        }
	</script>
	<style type="text/css">
		.ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default{
			background: #EFEFEF;
		}
		.usGroupUl{
			list-style: none;
			padding: 5px;
		}
		.usGroupUl li{
			list-style: none;
			font-size: 14px;
		}
		.usGroupUl li a{
			color: #333;
		}
		.new-dialog .ui-dialog-buttonset button{
			padding: 5px 10px;
		}
	</style>
</head>
<body>
<div style="clear: both;"></div>
<div id="dwBody" style="margin-top: 15px;" >
	<div id="dwBodyContent" class="bodyCenter" style="">
		<div id="dwBodyUser">
			<div class="surveyCollectMiddle">

				<div class="surveyCollectMiddleContent">
					<div style="padding: 25px 45px;overflow: auto;padding-top: 12px;">
						<div style="padding: 5px;color: #666565;letter-spacing: 2px;font-size: 18px;">活动</div>


						<div style="padding: 5px;color: #666565;text-align: right;float: right;margin-right: 20px;">
							<a href="${ctx }/sy/lottery/input.do" class="user-plus active"><i class="fa fa-plus " aria-hidden="true"></i>&nbsp;添加活动</a>
						</div>


						<div style="margin-top: 15px;">

							<div style="padding: 5px;color:#666565; ">

								<div>
									<table class="contacts-table"  cellpadding="0" cellspacing="0" width="100%">
										<tr>
											<th align="center" style="text-align: center;">编号</th>
											<th align="left">活动名称</th>
											<th align="left">开始时间</th>
											<th align="left">截止时间</th>
											<th align="center" style="text-align: center;">操作</th>
										</tr>
										<c:choose>
											<c:when test="${page.totalItems > 0}">
												<c:forEach items="${page.result }" var="en">
													<tr>
														<td align="left">${en.id }</td>
														<td align="left">${en.name }</td>
														<td align="left"><fmt:formatDate value="${en.startTime }" pattern="yyyy年MM月dd日"/></td>
														<td align="left"><fmt:formatDate value="${en.endTime }"   pattern="yyyy年MM月dd日"/></td>
														<td align="center">
															<a class="btn btn-default" href="#" title="奖项"data-toggle="tooltip" data-placement="top" onclick="setPrize('${en.id }')"><i class="fa fa-star-o "></i></a>
															<a class="btn btn-default" href="${ctx }/sy/lottery/user/list.do?id=${en.id}" title="中奖列表"data-toggle="tooltip" data-placement="top" ><i class="fa fa-align-justify"></i></a>
															<a class="btn btn-default" href="#" title="关联问卷"data-toggle="tooltip" data-placement="top" onclick="bindSurvey('${en.id }')"><i class="fa fa-link"></i></a>
															<a class="btn btn-default" href="#" title="删除"data-toggle="tooltip" data-placement="top" onclick="removeActivity('${en.id }')"><i class="fa fa-trash"></i></a>
															<a class="btn btn-default" href="${ctx }/sy/lottery/input.do?id=${en.id}" title="修改"data-toggle="tooltip" data-placement="top" ><i class="fa fa-pencil-square-o"></i></a>
														</td>
													</tr>
												</c:forEach>
											</c:when>
											<c:otherwise>
												<tr>
													<td colspan="13">
														<div style="padding: 60px;font-size: 22px;text-align: center;color: #b1aeae;">还没有数据！</div>

													</td>
												</tr>
											</c:otherwise>
										</c:choose>

									</table>
									<div style="padding-top: 15px;text-align: center;">
										<div class="btn-group">
											<c:if test="${page.pageNo > 1}">
												<a href="${ctx }/sy/lottery/list.do?pageNo=${page.pageNo-1}" class="btn btn-default pageIndex">&lt;</a>
											</c:if>
											<c:if test="${page.startpage > 1}">
												<a href="${ctx }/sy/lottery/list.do?pageNo=1" class="btn btn-default pageIndex">1</a>
												<c:if test="${page.startpage > 2 }">
													<%--<span>...</span>--%>
												</c:if>
											</c:if>
											<c:forEach begin="${page.startpage }" end="${page.endpage }" var="en">
												<c:choose>
													<c:when test="${page.pageNo eq en }"><a href="${ctx }/sy/lottery/list.do?pageNo=${en }" class="btn btn-default pageIndex" style="background: #D3DEED;">${en }</a></c:when>
													<c:otherwise><a href="${ctx }/sy/lottery/list.do?pageNo=${en}" class="btn btn-default pageIndex">${en }</a></c:otherwise>
												</c:choose>
											</c:forEach>
											<c:if test="${page.totalPage > (page.endpage)}">
												<c:if test="${page.totalPage > (page.endpage+1)}">
													<%--<span>...</span>--%>
												</c:if>
												<a href="${ctx }/sy/lottery/list.do?pageNo=${page.totalPage}" class="btn btn-default pageIndex">${page.totalPage }</a>
											</c:if>
											<c:if test="${page.totalPage > page.pageNo}">
												<a href="${ctx }/sy/lottery/list.do?pageNo=${page.pageNo+1}" class="btn btn-default pageIndex">&gt;</a>
											</c:if>

										</div>
										<c:if test="${page.totalItems > 0}">
											&nbsp;&nbsp;&nbsp;&nbsp;
											<input id="jumpPageNo" type="number" value='${page.pageNo}' min=1 max=${page.totalPage } style="padding: 4px;outline: none;border: 1px solid #83ABCB;width:60px">
											<a id ="jumpHref" href="javascript:void(0)" onclick='jumpPage()'  class="btn btn-default pageIndex" hidefocus="true" style="padding: 4px;margin-bottom: 4px;">GO</a>
											<script>
                                                function jumpPage(){
                                                    var min = 1;
                                                    var max = ${page.totalPage };
                                                    var jumpNo = document.getElementById("jumpPageNo").value;
                                                    if (jumpNo <= max && jumpNo >=min) {
                                                        var a = document.getElementById("jumpHref");
                                                        a.href = '${ctx }/sy/lottery/list.do?pageNo='+jumpNo;
                                                        $("#formSearch").attr("action",$("#jumpHref").attr("href"));
                                                        $("#formSearch").submit();
                                                    } else {
                                                        document.getElementById("jumpPageNo").value ='';
                                                        return false;
                                                    }
                                                }
											</script>
										</c:if>
									</div>

								</div>

							</div>
						</div>

					</div>

				</div>
			</div>

		</div>
	</div>
</div>



<script type="text/javascript">

    $("select[name='status']").val("${status}");

    resizeBodyWidth();
    $("a").attr("hidefocus",true);

</script>
</body>
</html>
